import { ref } from 'vue'

export interface IQColumn {
  name: string
  label: string
  field: string | ((row: any) => any)
  required?: boolean
  align?: 'left' | 'right' | 'center'
  sortable?: boolean
  sort?: (a: any, b: any, rowA: any, rowB: any) => number
  rawSort?: (a: any, b: any, rowA: any, rowB: any) => number
  sortOrder?: 'ad' | 'da'
  format?: (val: any, row: any) => string
  style?: string | ((row: any) => string)
  classes?: string | ((row: any) => string)
  headerStyle?: string
  headerClasses?: string
}
export type IQColumns = IQColumn[]
export type TQRows = Record<string, any>[]
export type TFilter = string | number | null

export function getTableConfig() {
  const selected = ref([])
  const totalRef = ref(0)

  const pagination = ref<Record<string, any>>({
    page: 1,
    rowsPerPage: 3
  })
  function paginationLabel() {
    // console.log(start, end, total, 'start, end, total')

    const pageNum = Math.ceil(totalRef.value / pagination.value.rowsPerPage)
    // console.log(pagination.value.rowsPerPage, pagination.value.page, pageNum, 'start, end, total')
    return `条  当前是:${pagination.value.page}/${pageNum}页 总条数:${totalRef.value}`
  }

  function selectedRowsLabel(numberOfRows: number) {
    // console.log(numberOfRows, 'numberOfRows')

    return `已选择${numberOfRows}条`
  }
  function onUpdatePagination(newPagination: IOption) {
    pagination.value = newPagination
    // console.log(newPagination, 'newPagination')
  }
  const filter = ref<string | number | null>('')
  return {
    selected,
    pagination,
    paginationLabel,
    selectedRowsLabel,
    onUpdatePagination,
    filter,
    totalRef
  }
}
